#include "ADC.h"
unsigned int adcin(unsigned char channel_select, unsigned char band_option)
        {
            unsigned int digital_data = 0;
            if((channel_select >= 0) && (channel_select <= 12 ))
            {
                channel_select <<= 2;
                ADCON0 = channel_select;
                ADCON0bits.GO = 0;
                ADCON0bits.ADON = 1;
                if (band_option == 0)
                { ADCON1bits.VCFG0 = 0;
                  ADCON1bits.VCFG1 = 0;}

                else if(band_option == 1)
                {  ADCON1bits.VCFG0 = 1;
                   ADCON1bits.VCFG1 = 1;}

                else if(band_option == 2)
                {  ADCON1bits.VCFG0 = 1;
                   ADCON1bits.VCFG1 = 0;}

                ADCON1 |= (14 - channel_select);
                ADCON2 = 0b10010110;
                __delay_us(10);

                ADCON0bits.GO = 1;
                while(ADCON0bits.GO == 1);
                if(PIR1bits.ADIF == 1)
                {
                  digital_data = ADRESH;
                  digital_data <<= 8;
                  digital_data |= ADRESL;
                  PIR1bits.ADIF = 0;
                }
                return digital_data;
            }
        }
